/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Controlador;

import Modelo.ENT_Feria;
import Modelo.ENT_Perfil;
import Modelo.ENT_TablaMov;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Isaac Paliza <anndysaac@hotmail.com>
 */
public class CTRL_Feria {
    private static ConnectionJDBC connectionJDBC = new ConnectionJDBC();
    private static Statement statement = connectionJDBC.createStatement();
    public static String Mensaje;
    
    public static List CargarFeria(String idFeria) throws SQLException{
        ArrayList<ENT_Feria> DatoKardex = new ArrayList();
        String sql = "SELECT C.idColegio, C.Nombre, C.Distrito, C.Direccion, "
                + "C.Representante, C.Descuento, F.Duracion "
                + "FROM (t_feria AS F "
                + "INNER JOIN t_colegio AS C ON F.idColegio = C.idColegio) "
                + "WHERE F.idFeria = " + idFeria ;
        ResultSet recordingResults =
                ConnectionJDBC.executeQuery(statement, sql);
        while (recordingResults.next()) {
            String idColegioAux = recordingResults.getString(1);
            if (recordingResults.wasNull()) {
                idColegioAux = "";
            }
            String NombreAux = recordingResults.getString(2);
            if (recordingResults.wasNull()) {
                NombreAux = "";
            }
            String DistritoAux = recordingResults.getString(3);
            if (recordingResults.wasNull()) {
                DistritoAux = "";
            }
            String DireccionAux = recordingResults.getString(4);
            if (recordingResults.wasNull()) {
                DireccionAux = "";
            }
            String RepresentanteAux = recordingResults.getString(5);
            if (recordingResults.wasNull()) {
                RepresentanteAux = "";
            }
            String DescuentoAux = recordingResults.getString(6);
            if (recordingResults.wasNull()) {
                DescuentoAux = "";
            }
            String DuracionAux = recordingResults.getString(7);
            if (recordingResults.wasNull()) {
                DuracionAux = "";
            }
            DatoKardex.add(new ENT_Feria(idColegioAux, NombreAux, DistritoAux, 
                    DireccionAux, RepresentanteAux, DescuentoAux, DuracionAux));
        }
        return DatoKardex;
    }

    public static List CargarMovimientoEntrada(String idFeria) throws SQLException {
        ArrayList<ENT_TablaMov> TablaMov = new ArrayList();
        String sql = "SELECT M.idTablaMov, L.nombre, M.precioU, M.cantidad, M.idLibro "
                + "FROM (t_tablamov AS M "
                + "INNER JOIN t_kardex AS K "
                + "ON M.idKardex = K.idKardex) "
                + "INNER JOIN t_libro AS L  "
                + "ON M.idLibro = L.idLibro "
                + "WHERE K.idFeria ="+idFeria+" AND M.idTipoMov = 1";
        ResultSet recordingResults =
                ConnectionJDBC.executeQuery(statement, sql);
        while (recordingResults.next()) {
            String idTablaMovAux = recordingResults.getString(1);
            if (recordingResults.wasNull()) {
                idTablaMovAux = "";
            }
            String nombreAux = recordingResults.getString(2);
            if (recordingResults.wasNull()) {
                nombreAux = "";
            }
            String precioUAux = recordingResults.getString(3);
            if (recordingResults.wasNull()) {
                precioUAux = "";
            }
            String cantidadAux = recordingResults.getString(4);
            if (recordingResults.wasNull()) {
                cantidadAux = "";
            }
            String idLibroAux = recordingResults.getString(5);
            if (recordingResults.wasNull()) {
                idLibroAux = "";
            }
            TablaMov.add(new ENT_TablaMov(idTablaMovAux, nombreAux, precioUAux, 
                    cantidadAux, idLibroAux));
        }
        return TablaMov;
    }

    public static List CargarListFeria() throws SQLException {
        ArrayList<ENT_Feria> ListaFeria = new ArrayList();
        String sql = "SELECT idFeria, nombre "
                + "FROM t_feria ";
        ResultSet recordingResults2
                = ConnectionJDBC.executeQuery(statement, sql);
        while (recordingResults2.next()) {
            String idFeriaAux = recordingResults2.getString(1);
            if (recordingResults2.wasNull()) {
                idFeriaAux = "";
            }
            String nombreAux = recordingResults2.getString(2);
            if (recordingResults2.wasNull()) {
                nombreAux = "";
            }
            ListaFeria.add(new ENT_Feria(idFeriaAux, nombreAux));
        }
        return ListaFeria;
    }
}
